package net.wangds.jpa.convertor;

import net.wangds.web.entrypoint.BaseMultipleResp;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;

@Component
public class Page2MultipleRespConv<T> implements Converter<Page<T>, BaseMultipleResp<T>> {
    @Override
    public BaseMultipleResp<T> convert(Page<T> source) {
        BaseMultipleResp res = BaseMultipleResp.list(source.getContent());
        res.pageIndexB1(source.getNumber()+1);
        res.pageSize(source.getSize());
        res.total(source.getTotalElements());
        return res;
    }
}
